package generics;

import java.util.Iterator;

public class IterableFibonacci2 implements Iterable<Integer>{
	int count;
	public IterableFibonacci2(int count){
		this.count = count;
	}
	private Fibonacci fib = new Fibonacci();
	
	
	public static void main(String[] args) {
		for(int i : new IterableFibonacci2(18))
			System.out.println(i);
	}

	public Iterator<Integer> iterator() {
		return new Iterator<Integer>(){
			public boolean hasNext() {
				return count > 0;
			}
			public Integer next() {
				count--;
				return fib.next();
			}
			public void remove() {
			}
		};
		
	}
}
